<script type="text/javascript">
	 selectTab('view_entries');
     var list_image = new Array();
</script>
<?php if (Core_Util::hasMessage(Core_Util::THANK_YOU_MSG)): ?>
	<div class="sm_message_panel">
		<p class="header">&nbsp;&nbsp;
			<?php echo $this->escape(Core_Util::getLatestMessage($this->contest->getThanksYouMgsKey())); ?>
		</p>
	</div>
<?php endif; ?>
<!--vote permission message-->
<?php if (count($this->is_allow_message)): ?>
	<div class="sm_message_panel">
		<?php foreach($this->is_allow_message as $msg):?>
			<p><?php echo $this->escape($msg);?></p>
		<?php endforeach;?>
	</div>
<?php endif; ?>
<div class="detail-container">
    <div id="slideImage">
        <div class="ContestPicture">
            <a class="pre_photo" title="Previous photo" >
            </a>
			<?php if(APP_INSTANCE == APP_INSTANCE_IMAGE):?>
				<img id="image_detail" src="<?php echo STATIC_URL . '/media/image/' . $this->entry->image; ?>"/>
			<?php else: ?>
				<div class="photo_container img" id="image_detail">
				<?php echo $this->entry->getEmbeddedCode() ?>
				</div>
			<?php endif;?>
            <a class="next_photo" title="Next photo" >
            </a>
        </div>
        <div id="slidePaging">
            <div class="PreviousPage">
                <a id="previous" title="Previous page" 
                   class="<?php if ($this->current == $this->first) echo "disabled"?>"
                   href="<?php echo $this->pageUrl(array_merge($this->extraValues, 
                                    array('target' => 'detail', 'id_entry' => null, 'status' => 'prev', 'page' => ($this->current > $this->first)? $this->page - 1: $this->page))); ?>">
                    
                </a>
            </div>
            <div class="ThisPageImages">
                <ul>
                    <?php 
                        $next_id_entry;
                        $current_id_entry;
                        $pre_id_entry;
                        
                        foreach ($this->paginator as $index => $entry) :
                            if (isset($current_id_entry) )
                            {
                                if (!isset($next_id_entry))
                                {
                                    $next_id_entry = $entry->id;
                                }
                            }
                            else 
                            {
                                if ($entry->id == $this->entry->id)
                                {
                                    $current_id_entry = $entry->id;
                                }
                                
                                if(!isset($current_id_entry))
                                {
                                    $pre_id_entry = $entry->id;
                                }
                            }
                    ?>
                    <script type="text/javascript">
                        list_image[<?php echo $index?>] = "<?php echo $entry->getThumbnailImageUrl() ?>";
                    </script>
                    
                        <li class="<?php if($entry->id == $this->entry->id) echo "Current";?>">
                            <a title="<?php echo $this->escape($entry->title) . ' - ' . $this->number($entry->votes,'LABEL_NUM_VOTE')?>"
                                href="<?php echo $this->pageUrl(array_merge($this->extraValues, 
                                        array('target' => 'detail', 'id_entry' => $entry->id))); ?>">
                                <img src="<?php echo $entry->getThumbnailImageUrl() ?>"/>
                            </a>
                        </li>
                    <?php 
                        endforeach;
                    ?>
                <ul>
            </div>
            <div class="NextPage">
                <a id="next" title="Next page" 
                   class="<?php if ($this->current == $this->last) echo "disabled"?>"
                    href="<?php echo $this->pageUrl(array_merge($this->extraValues, 
                            array('target' => 'detail', 'id_entry' => null, 'status' => 'next', 'page' => ($this->current < $this->last)? $this->page + 1: $this->page))); ?>">
                    
                </a>
            </div>
            <script type="text/javascript">
                $(".disabled").click(function(){
                    return false;
                });
                
                $(".ContestPicture").hover(
                    function(){
                        $(".pre_photo").show();
                        $(".next_photo").show();
                    }, 
                    function(){
                        $(".pre_photo").hide();
                        $(".next_photo").hide();
                    }
                );  
                    
                function pre_photo()
                {
                    <?php if (!isset($pre_id_entry)):?>
                        var pre_page_url = $("#previous").attr("href");
                        location.href = pre_page_url;
                    <?php else:?>
                        location.href = "<?php echo $this->pageUrl(array_merge($this->extraValues, 
                                array('target' => 'detail', 'id_entry' => $pre_id_entry, 'page' => $this->current))); ?>";
                    <?php endif;?>
                }
                
                function next_photo()
                {
                    <?php if (!isset($next_id_entry)):?>
                        var next_page_url = $("#next").attr("href");
                        location.href = next_page_url;
                    <?php else:?>
                        location.href = "<?php echo $this->pageUrl(array_merge($this->extraValues, 
                                array('target' => 'detail', 'id_entry' => $next_id_entry, 'page' => $this->current))); ?>";
                    <?php endif;?>
                }
                
                $(document).ready(function(){
                    <?php if (!isset($pre_id_entry) && $this->current == $this->first):?>
                        $(".pre_photo").attr("href", "javascript:{return false;}");
                        $(".pre_photo").addClass("disabled");
                    <?php else:?>
                        $(".pre_photo").attr("href", "javascript:pre_photo()");
                    <?php endif;?>
                        
                    <?php if (!isset($next_id_entry) && $this->current == $this->last):?>
                        $(".next_photo").attr("href", "javascript:{return false;}");
                        $(".next_photo").addClass("disabled");
                    <?php else:?>
                        $(".next_photo").attr("href", "javascript:next_photo()");
                    <?php endif;?>
                });
            </script>
        </div>  
    </div>
    <div class="entry_info">
        <div class="photo_detail">
            <strong><?php echo $this->escape($this->entry->title); ?></strong>
            <!--<a class="link_back" target="_top" href="<?php echo $this->social->pageUrl(array_merge($this->extraValues, array('target' => 'view'))); ?>">Back</a>-->
            <p>
                by 
                <a target="_blank" href="<?php echo $this->user_link;?>">
                    <?php echo $this->escape($this->entry->getCandidateName());?> 
                </a>
                on 
                <?php echo date('d M, Y', $this->entry->time_uploaded);?> 
                <!--| <?php echo $this->pageViews($this->entry->views);?>-->
            </p>
            <p class="entry-description">
                <?php echo nl2br($this->escape($this->entry->description)); ?>
            </p>
            <div class="social_plugin">
                <?php echo $this->social->render('recommendUrl', array(
                    'url'			=> $this->entry->getShareUrl(),
                    'id_object'		=> $this->entry->id,
                    'id_page'       => $this->id_page,
					'id_user'		=> $this->id_user?$this->id_user:ID_USER_CHEAT_FOR_COUNT_SHARE,
                    'show_text'		=> true,
                    'message'		=> YouNet_Util::escapeForJs(sprintf($this->translate('REQUEST_MESSAGE'), $this->contest->title, $this->contest->getPageName($this->id_page))),
                    'send'			=> false,
                    'show_faces'	=> false,
					'show_fb_like'	=> false
                )); ?>
            </div>
            <?php 
                echo $this->partial('detail-permanent.phtml', array('url' => $this->entry->getHrefWithIDUser($this->id_user)));
            ?>
        </div>

        <div class="vote_panel">
            <?php if($this->entry->status== Core_Model_IEntry::STATUS_APPROVED):?>
                <ul class="horizon">
                    <li>
                        <strong id="vote_number"><?php echo $this->number($this->entry->votes,'LABEL_NUM_VOTE'); ?></strong>
                        <input type='button' 
                               class='sm_button btn_vote <?php if(!$this->is_show_vote_button || $this->is_voted) echo "disabled";?>' 
                               id='btn_vote' 
                               value='<?php if($this->is_voted) echo "Voted"; else echo "Vote now";?>' />
                        
                    </li>
                </ul>
            <?php endif;?>
        </div>
    </div>
</div>

<?php if ($this->contest->isAllowedComment()): ?>
    <?php echo $this->social->render('comment',
        array(
            'url'	=> $this->entry->getCommentUrl(),
            'width' => 734
        ))
    ?>
    <script type="text/javascript">
        $(document).ready(function(){
            var url = '<?php echo $this->baseUrl('/contest/index/notify')?>';
            var data = {
                url: "<?php echo $this->entry->getHrefWithIDUser($this->id_user); ?>",
                id_contest: "<?php echo $this->contest->id?>"
            };
            detectNewComment(url, data, function(){});
        });
    </script>
<?php endif; ?>

<script type="text/javascript">
$(document).ready(function(){
<?php if( !$this->is_voted ):?>
	Social.hasPersmissions(function(result){			
			$('#btn_vote').click(function(e){
				if( !result )
				{
					Social.authorize(function(response){
						<?php if (empty($this->id_user)): ?>
							  Social.redirect("<?php echo $this->social->pageUrl(array_merge($this->extraValues, array('target' => 'vote', 'id_entry' => $this->entry->id))); ?>");
						<?php elseif ($this->is_show_vote_button && !$this->is_voted): ?>
							  Social.redirect("<?php echo $this->social->pageUrl(array_merge($this->extraValues, array('target' => 'vote', 'id_entry' => $this->entry->id))); ?>");
						<?php endif ?>
						},{
							scope: 'email,publish_stream',
							force: true,
							title: '<?php echo $this->translate('Cannot vote')?>',
							content: '<?php echo $this->translate('Please allow publish priviledge to post to wall')?>'
						}
					);
				}
				else
				{
					Social.redirect("<?php echo $this->social->pageUrl(array_merge($this->extraValues, array('target' => 'vote', 'id_entry' => $this->entry->id))); ?>");
				}
			});
		},{
			scope: 'email, publish_stream'
		}
	);
<?php endif ?>
    $(list_image).preload();
});
</script>
<?php echo $this->partial('index/scrollTop.phtml'); ?>